# Maintainer: Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=lis
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.1.10
pkgrel=1
pkgdesc='Library of Iterative Solvers for linear systems (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.ssisc.org/lis/'
msys2_repository_url="https://github.com/anishida/lis"
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             $([[ ${CARCH} == aarch64 ]] || echo "${MINGW_PACKAGE_PREFIX}-msmpi")
             "${MINGW_PACKAGE_PREFIX}-autotools")
options=('!docs')
source=(https://www.ssisc.org/lis/dl/${_realname}-${pkgver}.zip)
sha256sums=('14f72c1c277593447255c7c1e62873739850c540bb00774fe67bbe816c85d775')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  autoreconf -fiv
}

build() {
  [[ -d "build-${MSYSTEM}" ]] && rm -rf "build-${MSYSTEM}"
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  declare -a _extra_config
  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
      _extra_config+=("--disable-f90" "--disable-fortran")
  else
      _extra_config+=("--enable-f90" "--enable-fortran")
      export FFLAGS="-fallow-invalid-boz"
      CFLAGS+=" -fallow-invalid-boz -Wno-incompatible-pointer-types"
  fi

  if [[ ${CARCH} == x86_64 ]]; then
    _extra_config+=("--enable-mpi" "--enable-sse2" "--enable-fma")
  else
    _extra_config+=("--disable-mpi" "--disable-sse2" "--disable-fma")
  fi

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --enable-omp \
    --enable-shared \
    --enable-longlong \
    --enable-longdouble \
    --enable-quad \
    --enable-complex \
    --disable-test \
    --with-gnu-ld \
    ${extra_conf}

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"

  install -Dm644 COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

# vim: ts=2 sw=2 et:
